import axios from "@/utils/http";
// 数据
const state = {
  // 数据定义处
  // 获取挂号表格默认数据
  registerData: [],
  registerTotal: 1,
  // 获取点击按钮弹窗选择患者表格默认数据
  patientsData: [],
  patientsTotal: 1,
  // 医生下拉框
  doctorData: [],
  // 科室下拉框
  sectionData: [],
  // 挂号类别下拉框
  categoryData: [],
};

const getters = {
  //修饰后的数据获取方法
  //获取挂号表格默认数据
  getRegisterData(state: any) {
    let arr = state.registerData;
    return arr;
  },

  // 获取点击按钮弹窗选择患者表格默认数据
  getPatientsData(state: any) {
    let arr = state.patientsData;
    return arr;
  },

  // 医生下拉框
  getDoctorData(state: any) {
    let arr = <any>[];
    state.doctorData.forEach((item: any) => {
      if (item) arr.push(item.doctorName);
    });
    return arr;
  },

  // 科室下拉框
  getSectionData(state: any) {
    let arr = <any>[];

    state.sectionData.forEach((item: any) => {
      if (item) arr.push(item.department);
      if (item) arr.push(item.departmentId);
    });

    return arr;
  },

  // 挂号类别下拉框
  getCategoryData(state: any) {
    let arr = <any>[];
    state.categoryData.forEach((item: any) => {
      if (item) arr.push(item.regType);
      // console.log("categoryData",arr);
    });
    return arr;
  },
};

const mutations = {
  // 修改数据处 ，可在这写axios请求拿数据
  // 获取挂号表格默认数据
  setRegisterData(state: any, page: any) {
    axios({
      url: "/seeDoctor/consulting/registers",
      method: "get",
      params: {
        CurrentPage: page.CurrentPage,
        PageSize: page.PageSize,
      },
    })
      .then((res: any) => {
        console.log("左边默认表registerData格数", res.data);
        state.registerData = res.data.data;
        state.registerTotal = res.data.count;
      })
      .catch((err) => {
        console.log(err);
      });
  },

  // 点击按钮弹窗选择患者表格默认数据
  setPatientsData(state: any, page: any) {
    axios({
      url: "/seeDoctor/consulting/queryPas",
      method: "get",
      params: {
        // bankName: page.bankName,
        CurrentPage: page.CurrentPage,
        PageSize: page.PageSize,
      },
    })
      .then((res: any) => {
        console.log("选择患者表格", res);
        state.patientsData = res.data.data;
        state.patientsTotal = res.data.count;
      })
      .catch((err) => {
        console.log(err);
      });
  },

  // 弹窗内搜索->查询患者库患者信息
  setSearchNameData(state: any, page: any) {
    axios({
      url: "/seeDoctor/consulting/queryPa",
      method: "get",
      params: {
        bank_name: page.bank_name,
        // CurrentPage: page.CurrentPage,
        // PageSize: page.PageSize,
      },
    })
      .then((res: any) => {
        console.log("选择患者搜索出来的表格", res);
        state.patientsData = res.data.data;
        state.patientsTotal = res.data.count;
      })
      .catch((err) => {
        console.log(err);
      });
  },

  // 医生下拉框
  setDoctorList(state: any, page: any) {
    axios({
      url: "/seeDoctor/consulting/queryDoctor",
      method: "get",
      params: {},
    })
      .then((res: any) => {
        console.log("医生下拉框", res.data.data);
        state.doctorData = res.data.data;
      })
      .catch((err) => {
        console.log(err);
      });
  },

  // 科室下拉框
  setSectionList(state: any, page: any) {
    axios({
      url: "/seeDoctor/consulting/querydm",
      method: "get",
      params: {
        // department: page.department,
      },
    })
      .then((res: any) => {
        console.log("科室下拉框", res.data.data);
        state.sectionData = res.data.data;
      })
      .catch((err) => {
        console.log(err);
      });
  },

  // 挂号类别下拉框
  setCategoryList(state: any, page: any) {
    axios({
      url: "/seeDoctor/consulting/queryReq",
      method: "get",
      params: {},
    })
      .then((res: any) => {
        console.log("挂号类别下拉框", res.data.data);
        state.categoryData = res.data.data;
      })
      .catch((err) => {
        console.log(err);
      });
  },
  // 门诊挂号查询按钮接口
  setOutpatientsQuery(state: any, page: any) {
    axios({
      url: "/seeDoctor/consulting/register",
      method: "get",
      params: {
        CurrentPage: page.CurrentPage,
        PageSize: page.PageSize,
        doctor: page.doctor,
        departmentId: page.departmentId,
        regTypeId: page.regTypeId,
        remark: page.remark,
      },
    })
      .then((res: any) => {
        console.log("查询到的数据", res);
        state.registerData = res.data.data;
        state.registerTotal = res.data.data.length;
      })
      .catch((err) => {
        console.log(err);
      });
  },
  // 收费按钮
  setCharge(state: any, page: any) {
    axios({
      url: "/seeDoctor/consulting/submitConsulting",
      method: "get",
      data: {
        bankName: page.bankName,
        regType: page.regType,
        sex: page.sex,
        birthday: page.birthday,
        phone: page.phone,
        idNumber: page.idNumber,
        address: page.address,
        doctorName: page.doctorName,
        doctorShiftsld: page.doctorShiftsld,
      },
    })
      .then((res: any) => {
        console.log("点击收费后按钮获取到的数据", res);
        // state.registerData = res.data.data;
      })
      .catch((err) => {
        console.log(err);
      });
  },
  // 支付接口
  setPayFn(state: any, page: any) {
    axios({
      url: "/alipay",
      method: "get",
      params: {
        // 操作人姓名/挂号员
        message:page.message,
        // 诊断单编号，或者挂号单编号
        orderId:page.orderId,
        // 金额
        price:page.price,
        // 订单类型
        tradeType:1
      },
    })
      .then((res: any) => {
        console.log("支付后返回的数据", res);
        // state.registerData = res.data.data;
      })
      .catch((err) => {
        console.log(err);
      });
  },
};

const actions = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
